Fixes. Xen console buffer ring can be cleared at request.
#include "dom0_defs.h"
-#define CONSOLE_RING_SIZE 16392
+#define CONSOLE_RING_SIZE 16392
+#define CONSOLE_RING_CLEAR 1
+
static char *argv0 = "read_console_ring";
-static long read_console_ring(unsigned long str, unsigned count)
+static long read_console_ring(unsigned long str, unsigned count, unsigned int cmd)
{
int ret;
dom0_op_t op;
op.cmd = DOM0_READCONSOLE;
op.u.readconsole.str = str;
op.u.readconsole.count = count;
+ op.u.readconsole.cmd = cmd;
ret = do_dom0_op(&op);
if (ret > 0) {
int main(int argc, char **argv)
{
- char str[CONSOLE_RING_SIZE];
-
+ char str[CONSOLE_RING_SIZE+1];
+ unsigned int cmd = 0;
+
if ( argv[0] != NULL )
argv0 = argv[0];
- if ( argc > 2) {
- fprintf(stderr, "Usage: %s [-r]\n", argv0);
+ if ( argc > 2 || (argc == 2 && strcmp(argv[1], "-c")) ) {
+ fprintf(stderr, "Usage: %s [-c]\n", argv0);
+ return 1;
+ }
+
+ if ( argc == 2) {
+ cmd |= CONSOLE_RING_CLEAR;
+ }
+
+ if ( mlock(str, CONSOLE_RING_SIZE+1) != 0) {
+ PERROR("Could not lock memory for user space read console ring buffer");
return 1;
}
- if ( read_console_ring((unsigned long)str, CONSOLE_RING_SIZE) < 0 ) {
+ if ( read_console_ring((unsigned long)str, CONSOLE_RING_SIZE, cmd) < 0 ) {
printf("Read console ring error.\n");
- printf("%s", str);
return 1;
}
printf("%s", str);
+
return 0;
}
.len = 0
};
-void init_console_ring()
-{
- console_ring.len = 0;
-}
-
-long read_console_ring(unsigned long str, unsigned int count)
+long read_console_ring(unsigned long str, unsigned int count, unsigned cmd)
{
unsigned int len;
- len = (console_ring.len < count)? console_ring.len : count;
+ len = (console_ring.len < count) ? console_ring.len : count;
if ( copy_to_user((char *)str, console_ring.buf, len) )
return -EFAULT;
+ if ( cmd & CONSOLE_RING_CLEAR ) {
+ console_ring.len = 0;
+ }
+
return len;
}
case DOM0_READCONSOLE:
{
- extern long read_console_ring(unsigned long, unsigned int);
+ extern long read_console_ring(unsigned long, unsigned int, unsigned int);
ret = read_console_ring(op.u.readconsole.str,
- op.u.readconsole.count);
+ op.u.readconsole.count,
+ op.u.readconsole.cmd);
}
break;
{
unsigned long str;
unsigned int count;
+ unsigned int cmd;
} dom0_readconsole_t;
typedef struct dom0_op_st
* Copyright (c) 2003 James Scott, Intel Research Cambridge
*/
+#ifndef __CONSOLE_H__
+#define __CONSOLE_H__
+
/*
* Ownership of console --- currently hardwired to dom0. This is used to see
* who gets the PS/2 keyboard/mouse events
extern int opt_console;
-#define CONSOLE_RING_SIZE 16392
+#define CONSOLE_RING_SIZE 16392
+#define CONSOLE_RING_CLEAR 1
typedef struct console_ring_st
{
extern console_ring_t console_ring;
-void init_console_ring();
-long read_console_ring(unsigned long, unsigned int);
+long read_console_ring(unsigned long, unsigned int, unsigned int);
+
+#endif